#if 0

#include "Engine.glut.h"
#include "Object.h"
#include "Draw.h"
#include "Timing.h"
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>

// ---------------------------------------------------------------
static Engine* engine = NULL;
// --------------------------------------------------------------------

// ---------------------------------------------------------------
Engine::Engine(void)
    :
    running(false), server(false), width(480), height(480), imageID(0),
    keyMap(), objetos(),
    socket(666,true),packet(256)
{
    engine = this;
}
// ---------------------------------------------------------------
Engine::~Engine(void)
{
    shutdown();
}
// ---------------------------------------------------------------
Object& Engine::addObject(void)
{
    Object obj;
    objetos.push_back(obj);
    return objetos[objetos.size()-1];
}
// ---------------------------------------------------------------
int Engine::loadTexture( const char* filename )
{
    return ilutGLLoadImage( (char*) filename);
}
// ---------------------------------------------------------------
void Engine::loop(void)
{
	glutMainLoop();
}
// ---------------------------------------------------------------
void Engine::setKeyState( int keyCode, bool state )
{
	keyMap[ keyCode ] = state;

	std::cout << "tecla: " << keyCode << std::endl;
}
// ---------------------------------------------------------------
bool Engine::getKeyState( int keyCode )
{
	if( keyMap.find(keyCode) == keyMap.end() )
		return false;

	return keyMap[ keyCode ];
}
// ---------------------------------------------------------------
void Engine::keyboardFunc( unsigned char key, int x, int y )
{
	if( !engine || (engine->server) ) return;

	static Timing timer;
	static bool done = false;
	if( !done )
	{
		timer.resume();
		done = true;
	}


	timer.tick();
	Object& obj = engine->objetos[1];
	double t = timer.getElapsedTime()*0.05;
	t = 1.0/60.0;

	Vetor2d eixo = Vetor2d::fromAngle( obj.angle );

	switch( key  )
	{
	case 'w': case 'W':
		//std::cout << "up" << std::endl;
		obj.posicao += eixo*0.2*t;
		break;
	case 's': case 'S':
		//std::cout << "down" << std::endl;
		obj.posicao -= eixo*0.2*t;
		break;
	case 'a': case 'A':
		//std::cout << "left" << std::endl;
		obj.angle += 45*t;
			break;
	case 'd': case 'D':
		//std::cout << "right" << std::endl;
		obj.angle -= 45*t;
		break;
	case ' ':
		std::cout << "space" << std::endl;
		break;
	}

	obj.posicao.x = std::min( obj.posicao.x, 0.9f );
	obj.posicao.x = std::max( obj.posicao.x,-0.9f );

	obj.posicao.y = std::min( obj.posicao.y, 0.9f );
	obj.posicao.y = std::max( obj.posicao.y,-0.9f );

	//char pacote[128];
	engine->packet.setAddress("127.0.0.1");
	engine->packet.setPort( 666 );


	memset( engine->packet.getBuffer(), 0, 256 );
	sprintf( (char*) engine->packet.getBuffer(), "%f %f %f", obj.posicao.x, obj.posicao.y, obj.angle );

	engine->socket.send( engine->packet );
	//pakcet->send( &pacote[0], sizeof(pacote) );
}
// ---------------------------------------------------------------
void Engine::reshapeFunc( int w, int h )
{
	if( !engine ) return;

	engine->resizeWindow( w, h);
}
// ---------------------------------------------------------------
void Engine::displayFunc(void)
{
	if( !engine ) return;

	engine->drawScene();
}
// ---------------------------------------------------------------
void Engine::idleFunc(void)
{
	if( engine && engine->server )
	{
		if(engine->socket.receive(engine->packet ) )
		{
			Object& obj = engine->objetos[1];
			sscanf( engine->packet.getBuffer(), "%f %f %f", &(obj.posicao.x), &(obj.posicao.y), &(obj.angle) );
		}
	}
}
// ---------------------------------------------------------------
bool Engine::init(const EngineParameters& params)
{
	EngineParameters& ep = const_cast<EngineParameters&>(params);

	server = (params.argc > 1) && (strcmp(params.argv[1], "server") == 0 );
	std::cout << "server? " << server << std::endl;


	glutInit(  &ep.argc, ep.argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );

	glutInitWindowPosition( 500,100 );
	glutInitWindowSize( width, height );

	if( server )
		glutCreateWindow("Tank Multiplayer [server]");
	else
		glutCreateWindow("Tank Multiplayer [client]");

	glutKeyboardFunc( Engine::keyboardFunc  );
	//glutKeyboardUpFunc(  );
	glutReshapeFunc( Engine::reshapeFunc );
	glutDisplayFunc( Engine::displayFunc );
	glutIdleFunc( Engine::idleFunc );



	// OpenIL
	ilutRenderer(ILUT_OPENGL);
	ilInit();
	iluInit();
	ilutInit();
	ilutRenderer(ILUT_OPENGL);

	ilGenImages( 1, &imageID );
	ilBindImage( imageID );


    return true;
}
// ---------------------------------------------------------------
void Engine::shutdown(void)
{
    ilDeleteImage( imageID );
     imageID = 0;

    // OpenIL
    ilShutDown();

    //dtor
#ifdef WIN32
    if( hRC )
    {
        wglMakeCurrent(NULL, NULL);
        wglDeleteContext(hRC);
        hRC = NULL;
    }

    if( hwnd && hDC )
    {
        ReleaseDC(hwnd, hDC);
        hDC = NULL;
    }

    /* destroy the window explicitly */
    if(hwnd)
    {
            DestroyWindow(hwnd);
            hwnd = NULL;
    }
#else
    // TODO fazer o mesmo no Linux
#endif
}

//static float px = 0, py = 0;
// ---------------------------------------------------------------
void Engine::resizeWindow( unsigned int _width, unsigned int _height )
{
    width  = _width;
    height = _height;

    glViewport(0,0,width, height);

    // NOTA: melhora o desempenho
    //glEnable(GL_SCISSOR_TEST);
    //glScissor( 0,0, width, height);


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();    // rescala o Y
    float sy = (height) ? ((float)width/(float)height): 1.0f;
    glScalef( 1.0f, sy, 1.0f);
    glMatrixMode(GL_MODELVIEW);
}


// ---------------------------------------------------------------
void Engine::drawScene(void)
{
    static float theta =0;

    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();

    for( unsigned int i=0; i<objetos.size() ; ++i )
    {
        glPushMatrix();
            glLoadIdentity();
            objetos[i].draw();
        glPopMatrix();
    }

    static Material opaco;
    opaco.cor.set(0.75f,1,0.75f,0.9f);
    opaco.texturaHabilitada = false;
    opaco.usarMaterial();

    static float angle = 45;

    angle += 0.6f;

    glFlush();
#ifdef WIN32
    SwapBuffers(hDC);
#else
    // TODO disparar a troca dos buffers no windows
    //glXSwapBuffers(dpy, win);
    glutSwapBuffers();
    glutPostRedisplay();
#endif

    theta += 1.0f;
    //Sleep (1);
}
// ---------------------------------------------------------------
void Engine::drawQuad(void)
{
    // TODO dar uma cor
    glBegin(GL_QUADS);
        //glColor3f(1.0f, 1.0f, 1.0f);
        //const Cor& cor = Cor::COLOR_GREEN;
        //glColor4f( cor.r, cor.g, cor.b, cor.a );

        glTexCoord2f(0.0f,0.0f);        glVertex2f( -1.0f, -1.0f);
        glTexCoord2f(1.0f,0.0f);        glVertex2f( +1.0f, -1.0f);
        glTexCoord2f(1.0f,1.0f);        glVertex2f( +1.0f, +1.0f);
        glTexCoord2f(0.0f,1.0f);        glVertex2f( -1.0f, +1.0f);

    glEnd();
}
// ---------------------------------------------------------------
#endif
